package org.example.app.bean;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 内容销售数据累加器 - 用于Flink聚合操作
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ContentSalesAccumulator {
    
    // 内容基本信息
    public String contentId;
    public String contentTitle;
    public String contentType;
    public String shopId;
    public String shopName;
    
    // 累计度量值
    public Long totalViewCount = 0L;
    public Long totalClickCount = 0L;
    public Long totalOrderCount = 0L;
    public Double totalSalesAmount = 0.0;
    public Double avgConversionRate = 0.0;
    public Integer count = 0;
    
    // 窗口时间信息
    public Long windowStart;
    public Long windowEnd;
    
    /**
     * 重置累加器
     */
    public void reset() {
        this.totalViewCount = 0L;
        this.totalClickCount = 0L;
        this.totalOrderCount = 0L;
        this.totalSalesAmount = 0.0;
        this.avgConversionRate = 0.0;
        this.count = 0;
    }
    
    /**
     * 计算平均转化率
     */
    public void calculateAvgConversionRate() {
        if (totalViewCount > 0) {
            this.avgConversionRate = totalOrderCount.doubleValue() / totalViewCount * 100;
        }
    }
}